import { defineStore } from 'pinia'
import config from "@/config"

export const useGlobalStore = defineStore('global', {
	state: () => ({
		// 移动端布局
		ismobile: false,
		// 布局
		layout: config.LAYOUT,
		// 菜单是否折叠 toggle
		menuIsCollapse: config.MENU_IS_COLLAPSE,
		// 多标签栏
		layoutTags: config.LAYOUT_TAGS,
		// 主题
		theme: config.THEME,
	}),
	
	getters: {
		// 获取是否移动端
		getIsMobile: (state) => state.ismobile,
		// 获取布局配置
		getLayout: (state) => state.layout,
		// 获取菜单折叠状态
		getMenuIsCollapse: (state) => state.menuIsCollapse,
		// 获取标签栏状态
		getLayoutTags: (state) => state.layoutTags,
		// 获取主题
		getTheme: (state) => state.theme,
	},
	
	actions: {
		// 设置移动端状态
		setIsMobile(value) {
			this.ismobile = value
		},
		
		// 设置布局
		setLayout(value) {
			this.layout = value
		},
		
		// 设置主题
		setTheme(value) {
			this.theme = value
		},
		
		// 切换菜单折叠状态
		toggleMenuIsCollapse() {
			this.menuIsCollapse = !this.menuIsCollapse
		},
		
		// 切换标签栏状态
		toggleLayoutTags() {
			this.layoutTags = !this.layoutTags
		}
	}
})